#include <bits/stdc++.h>
#include <map>
#define debug(x) cout<<#x<<":"<<x<<endl
using namespace std;
map<string,int> mp;
int n;

string change(int num)
{
	string ret;
	int p=0;
	while(num>0)
	{
		ret+=(num%10)+'0';
		num/=10;
	}
	for(int i=0,j=ret.size()-1;i<j;i++,j--)
		swap(ret[i],ret[j]);
	return ret;
}

bool check(string str)
{
	int a,b,c,d,e;
	sscanf(str.c_str(),"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
	if((0<=a&&a<=255)==false) return false;
	if((0<=b&&b<=255)==false) return false;
	if((0<=c&&c<=255)==false) return false;
	if((0<=d&&d<=255)==false) return false;
	if((0<=e&&e<=65535)==false) return false;
	string t=change(a)+"."+change(b)+"."+change(c)+"."+change(d)+":"+change(e);
//	debug(t);debug(str);
	return t==str;
}

int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
//	cout<<check("192.168.1.1:8080");
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string a,b;
		cin>>a>>b;
		if(a=="Server")
		{
			if(check(b)&&mp[b]==0)
				cout<<"OK"<<endl,mp[b]=i;
			else if(check(b)==false)
				cout<<"ERR"<<endl;
			else if(mp[b]!=0)
				cout<<"FAIL"<<endl;
		}
		if(a=="Client")
		{
			if(check(b)&&mp[b]!=0)
				cout<<mp[b]<<endl;
			else if(check(b)==false)
				cout<<"ERR"<<endl;
			else if(mp[b]==0)
				cout<<"FAIL"<<endl;
		}
	}
	return 0;
}
/*
5
Server 192.168.1.1:8080
Server 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.1:99999
*/
